package net.awpspace.mobile.management.contact;


import javax.microedition.midlet.MIDlet;

import com.sun.lwuit.Button;
import com.sun.lwuit.ButtonGroup;
import com.sun.lwuit.ComboBox;
import com.sun.lwuit.Command;
import com.sun.lwuit.Container;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.RadioButton;
import com.sun.lwuit.TextField;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BoxLayout;

import net.awpspace.mobile.form.BaseForm;

public class AddContact extends BaseForm {
	TextField hovaten,sdt,email,diachi,nhom,mang;
	Label label_choise,label_cmbox;
	RadioButton choise1,choise2,choise3;
	List list;
	public AddContact(MIDlet app, BaseForm parent) {
		super(app, parent);
		setTitle("Quản lý danh bạ");
		Button addcontact = new Button(new Command("Lưu"));
		Button addcontact1 = new Button(new Command("Reset"));
		Container container = new Container(new BoxLayout(BoxLayout.Y_AXIS));
		container.addComponent(new Label("Họ và tên:"));
		hovaten = new TextField();
		hovaten.setRows(1);
		container.addComponent(hovaten);
		container.addComponent(new Label("Số điện thoại :"));
		sdt = new TextField();
		container.addComponent(sdt);
		container.addComponent(new Label("Email :"));
		email = new TextField();
		container.addComponent(email);
		sdt.setRows(1);
		container.addComponent(new Label("Địa chỉ:"));
		diachi = new TextField();
		diachi.setRows(2);
		container.addComponent(diachi);
		
		label_choise = new Label("Chọn nhóm: ");
		ButtonGroup groups = new ButtonGroup();
		choise1 = new RadioButton();
		choise1.setText("Gia Đình");
		choise2 = new RadioButton();
		choise2.setText("Bạn bè");
		choise3 = new RadioButton();
		choise3.setText("Xã Hội");
		groups.add(choise1);
		groups.add(choise2);
		groups.add(choise3);
		container.addComponent(label_choise);
		
		container.addComponent(choise1);
		container.addComponent(choise2);
		container.addComponent(choise3);
		
		list = new List();
		list.addItem("Viettel");
		list.addItem("Vinafone");
		list.addItem("Mobifone");
		list.addItem("Khác");
		label_cmbox = new Label("Chọn mạng: ");
		container.addComponent(label_cmbox);
		ComboBox cmbox= new ComboBox(list.getModel());
		container.addComponent(cmbox);
		
		
		container.addComponent(addcontact);
		container.addComponent(addcontact1);
		this.addComponent(container);
		// TODO Auto-generated constructor stub
	}

	protected void processCommand(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getCommand().getCommandName().equals("Lưu")){
			String Name = hovaten.getText();
			String Sdt = sdt.getText();
			String Email = email.getText();
			String Diachi = diachi.getText();
			
			Data.data= Name;
			Data.data1= Sdt; 
			Data.data2 = Email;
			Data.data3 = Diachi;
		
		String	Nhom = null;
		String  Mang = null;
		
		if(choise1.isSelected())  Nhom="Gia đình";
		else if (choise2.isSelected()) Nhom= "Bạn bè";
		else  Nhom= "Xã hội";
		Data.data4 = Nhom;
		
	
		if(list.getSelectedIndex()==0)  Mang="Viettel";
		else if(list.getSelectedIndex()==1) Mang="Vinafone";
		else if(list.getSelectedIndex()==2) Mang="Mobifone";
		else Mang="Khac";
				Data.data5=Mang;
		
		}
		
		else if(e.getCommand().getCommandName().equals("Reset")){
			hovaten.setText("");
			sdt.setText("");
			email.setText("");
			diachi.setText("");
			
		}
		
	}
	
}
